package cn.mdx.controller;

import cn.mdx.common.beans.ResultBean;
import cn.mdx.common.beans.User;
import cn.mdx.mapper.DemandMapper;
import cn.mdx.pojo.*;
import cn.mdx.service.DemandService;
import cn.mdx.service.ResourceService;
import cn.mdx.service.ResultService;
import cn.mdx.service.VoService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.io.IOException;

@SuppressWarnings({"ALL", "AlibabaClassMustHaveAuthor"})
@RestController
@Controller
@RequestMapping("/skill")
@CrossOrigin
public class SkillController {

    @Autowired
    private ResourceService resourceService;

    @Autowired
    private VoService voService;

    @Autowired
    private ResultService resultService;


    @Autowired
    private DemandService demandService;

    /**
     *
     * @param patent 专利资源的一些参数
     * @param pic 图片文件
     * @return
     * @throws IOException
     */
    @PostMapping("/addPatent")
    public ResultBean addPatent(Patent patent, HttpSession session, MultipartFile pic) throws IOException {
        resourceService.addPatent(patent,pic,session,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/getPatent")
    public ResultBean getPatent(Integer id, HttpSession session)  {
        return new ResultBean(resourceService.getPatent(id,User.getId(session)));
    }

    @PostMapping("/setPatent")
    public ResultBean setPatent(Patent patent, MultipartFile pic, HttpSession session) throws IOException {
        resourceService.setPatent(patent, pic, session,User.getId(session));
        return new ResultBean();
    }




    @PostMapping("/addSchool")
    public ResultBean addSchool(School school, HttpSession session, MultipartFile pic) throws IOException {
        resourceService.addSchool(school,pic,session,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/getSchool")
    public ResultBean getSchool(Integer id, HttpSession session)  {
        return new ResultBean(resourceService.getSchool(id,User.getId(session)));
    }

    @PostMapping("/setSchool")
    public ResultBean setSchool(School school, MultipartFile pic, HttpSession session) throws IOException {
        resourceService.setSchool(school, pic, session,User.getId(session));
        return new ResultBean();
    }



    @PostMapping("/addSoftware")
    public ResultBean addSoftware(Software software, HttpSession session, MultipartFile pic) throws IOException {
        resourceService.addSoftware(software,pic,session,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/getSoftware")
    public ResultBean getSoftware(Integer id, HttpSession session)  {
        return new ResultBean(resourceService.getSoftware(id,User.getId(session)));
    }

    @PostMapping("/setSoftware")
    public ResultBean setSoftware(Software software, MultipartFile pic, HttpSession session) throws IOException {
        resourceService.setSoftware(software, pic, session,User.getId(session));
        return new ResultBean();
    }



    @PostMapping("/addTeam")
    public ResultBean addTeam(Team team, HttpSession session, MultipartFile pic) throws IOException {
        resourceService.addTeam(team,pic,session,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/getTeam")
    public ResultBean getTeam(Integer id, HttpSession session)  {
        return new ResultBean(resourceService.getTeam(id,User.getId(session)));
    }

    @PostMapping("/setTeam")
    public ResultBean setTeam(Team team, MultipartFile pic, HttpSession session) throws IOException {
        resourceService.setTeam(team, pic, session,User.getId(session));
        return new ResultBean();
    }



    @PostMapping("/addTerrace")
    public ResultBean addTerrace(Terrace terrace, HttpSession session, MultipartFile pic) throws IOException {
        resourceService.addTerrace(terrace,pic,session,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/getTerrace")
    public ResultBean getTerrace(Integer id, HttpSession session)  {
        return new ResultBean(resourceService.getTerrace(id,User.getId(session)));
    }

    @PostMapping("/setTerrace")
    public ResultBean setTerrace(Terrace terrace, MultipartFile pic, HttpSession session) throws IOException {
        resourceService.setTerrace(terrace, pic, session,User.getId(session));
        return new ResultBean();
    }

    @RequestMapping("/delService")
    public ResultBean delService(Integer sid, HttpSession session) {
        resourceService.delService(sid, session,User.getId(session));
        return new ResultBean();
    }

    @RequestMapping("/getServices")
    public ResultBean getServices(HttpSession session) {
        User user = (User) session.getAttribute("user");
        return new ResultBean(voService.getServiceById(user.getId()));
    }

    @RequestMapping("/getServiceId")
    public ResultBean getServicesId(HttpSession session) {
        User user = (User) session.getAttribute("user");
        return new ResultBean(resourceService.getServicesId(user.getId()));
    }

    @PostMapping("/addResult")
    public ResultBean addResult(Result result, HttpSession session) {
        resultService.addResult(result,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/setResult")
    public ResultBean setResult(Result result, HttpSession session) {
        resultService.setResult(result,User.getId(session));
        return new ResultBean();
    }

    @RequestMapping("/delResult")
    public ResultBean delResult(Integer rid, HttpSession session) {
        resultService.delResult(rid,User.getId(session));
        return new ResultBean();
    }

    @PostMapping("/getResult")
    public ResultBean getResult(Integer rid, HttpSession session){
        return new ResultBean(resultService.getResult(rid,User.getId(session)));
    }

    @PostMapping("/getDemands")
    public ResultBean getDemands(Integer page, String info){
        return new ResultBean(demandService.getDemands(page,info));
    }

    @PostMapping("/getDemand")
    public ResultBean getDemand(Integer id){
        return new ResultBean(demandService.getDemand(id));
    }

    @PostMapping("/findResultVo")
    public ResultBean findResultVo(Integer rid){
        return new ResultBean(voService.findResultVO(rid));
    }


    @RequestMapping("/getResultList")
    public ResultBean getResultList(HttpSession session) {
        return new ResultBean(resultService.getResultList(User.getId(session)));
    }
}
